package com.cz.nongyetongv5.utils;


import java.io.UnsupportedEncodingException;

import org.apache.http.entity.ByteArrayEntity;

import android.content.Context;
import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;


public class AsyncClienter {

	public static AsyncHttpClient mClient = new AsyncHttpClient();
	static {
		mClient.setTimeout(10000);
	}
	public static void post(String url, AsyncHttpResponseHandler handler) {
		post(url, null, handler);
	}

	public static void post(String url, RequestParams params,
							AsyncHttpResponseHandler handler) {
		mClient.post(url, params, handler);
	}
	public static void get(String url, AsyncHttpResponseHandler handler) {
		mClient.setBasicAuth("apis", "35337f1232b9b5c92996e059174ef735");
		mClient.get(url,   handler);
	}
	public static void get(String url, RequestParams params,
						   AsyncHttpResponseHandler handler) {
		mClient.setBasicAuth("apis", "35337f1232b9b5c92996e059174ef735");
		mClient.get(url, params, handler);
	}
	public static void Ws(Context context,String url,String param,
						  AsyncHttpResponseHandler handler) {
		Ws(  context,url,  param,handler,"http://tempuri.org/GetTaskDetail");

	}
	public static void Ws(Context context,String url,String param,
						  AsyncHttpResponseHandler handler,String action) {
		Log.d("请求数据",param);
		ByteArrayEntity entity=null;
		try {
			entity = new ByteArrayEntity(param.toString().getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return ;
		}
		mClient.addHeader("SOAPAction",action);
		mClient.post(context,url,entity, "text/xml;charset=utf-8", handler);
	}
}